<template>
	<view class="statistics">
		<u-navbar title="统计需冷量" title-size="36" title-color="#333333"></u-navbar>
		
		<view class="uForm">
			<u-field
				v-model="sampleVariety"
				label="样品品种"
				required
				input-align="right"
				placeholder="请填写"
			>
			</u-field>
			<u-field
				v-model="sampleNo"
				label="样品编号"
				required
				input-align="right"
				placeholder="请填写"
			>
			</u-field>
			<u-field
				v-model="collectTime"
				label="采集日期"
				required
				disabled
				input-align="right"
				placeholder="请选择"
				right-icon="arrow-right"
				@click="show = true"
			>
			</u-field>
			<u-picker v-model="show"
				mode="time" 
				confirm-color="#00A1F2" 
				:params="params"
				:default-time="defaultTime"
				@confirm="onTimeConfirm"></u-picker>
			<u-field
				v-model="germinationRateString"
				label="萌芽率"
				required
				disabled
				input-align="right"
				placeholder="请选择"
				right-icon="arrow-right"
				@click="showRate = true"
			>
			</u-field>
			<u-picker v-model="showRate"
				mode="selector" 
				confirm-color="#00A1F2" 
				:range="selector"
				@confirm="onRateConfirm"></u-picker>
		</view>
		<view class="home-tips">
			<view class="tip-title">
				温馨提示：
			</view>
			<view class="tip-content">
				1、萌芽标准：最低萌芽标准为叶芽、花芽顶端鳞片开裂、露绿。<br />
				2、统计标准：如萌芽率为50%-60%，则需冷量统计以本次采样时间为准；若萌芽率60%-70%，则以本次与上一次采样时间需冷量的平均值为准；若萌芽率大于70%，则需冷量统计以上一次采样时间的需冷量为准。<br />
				3、分别于梨树自然落叶后，每隔5天，采集树冠外围和上部叶芽或腋花芽芽体饱满充实的枝条，每品种每次采集20枝，剪去两端，枝条留30-40cm长，枝条基部留5-10cm无芽部分，插入盛有清水（水深约3cm）的烧杯中，每3天换1次水，每次剪去枝条基部少许（约2mm）露出新茬；烧杯置于人工气候箱中，培养条件：温度昼/夜（12h/12h）：25℃/15℃，光照光/暗时数：14h/10h ，光照强度：1000-1200mol/m2·s，空气相对湿度60%-65%。连续培养3周后统计花芽的萌芽率。
			</view>
		</view>
		
		<view class="coin-btn">
			<u-button type="primary" @click="onSubmit" :disabled="btnDisabled" shape="circle" >开始评测</u-button>
		</view>
	</view>
</template>

<script>
let selector = []
for(let i = 1; i <= 100; i++) {
	selector.push(i)
}
export const dD = (val) => {
	if(val > 9) {
		return val
	} else {
		return '0' + val
	}
}
export default {
	data() {
		let date = new Date()
		date = date.getFullYear() + '-' + dD(date.getMonth() + 1) + '-' + dD(date.getDate())
		return {
			show: false,
			showRate: false,
			params: {
				year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false
			},
			selector,
			btnDisable: false,
			defaultTime: date,
			collectTime: date,
			germinationRate: null,
			germinationRateString: null,
			sampleNo: null,
			sampleVariety: null
		}
	},
	computed: {
		btnDisabled() {
			if(!this.collectTime || !this.germinationRate || !this.sampleNo || !this.sampleVariety) {
				return true
			}
			return false
		}
	},
	methods: {
		onSubmit() {
			this.$u.post('/public/lipingggu/addLipingguChillingRequirementRecord', {
				collectTime: this.collectTime,
				germinationRate: this.germinationRate,
				sampleNo: this.sampleNo,
				sampleVariety: this.sampleVariety
			}).then(res => {
				if(res && res.msg == -1) {
					uni.showToast({
						title: res.chillingRequirementTypeDesc,
						icon: 'error'
					});
					return
				}
				uni.showToast({
					title: '评测完成'
				});
				setTimeout(() => {
					this.$u.route({
						type: 'redirectTo',
						url: '/pages/subPage/result',
						params: {
							chillingRequirementSum: res.chillingRequirementSum,
							chillingRequirementTypeDesc: res.chillingRequirementTypeDesc
						}
					})
				}, 500)
			})
		},
		onTimeConfirm(val) {
			this.collectTime = `${val.year}-${val.month}-${val.day}`
		},
		onRateConfirm(val) {
			// 返回的索引
			let selectRate = this.selector[val[0]]
			this.germinationRateString = selectRate + '%'
			this.germinationRate = selectRate / 100
		}
	}
}
</script>

<style lang="less" scoped>
.statistics {
	background-color: #F7F7F7;
	min-height: 100vh;
}
.home-tips {
	padding: 48rpx;
	font-size: 24rpx;
	color: #333333;
	.tip-content {
		line-height: 40rpx;
		opacity: 0.6;
		padding-top: 24rpx;
		text-align: justify;
	}
}
.uForm {
	background-color: #FFFFFF;
	padding: 0 24rpx;
}
.coin-btn {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	padding: 24rpx 32rpx;
	border-top: 2rpx solid #E6E6E6;
	background-color: #FFFFFF;
}
/deep/.u-btn--primary {
	line-height: 96rpx;
	background: #00A1F2 !important;
	box-shadow: 0 16rpx 48rpx rgba(0, 0, 0, 0.06);
	border-radius: 48rpx;
	color: #fff !important;
	font-size: 36rpx;
	
}
</style>
